<script>
	import {getAccToken,getRefToken,setAccToken,setRefToken} from 'userToken.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
				// this.isOpenMode()
				
			// setAccToken('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MzE0NCwiZXhwIjoxNzAxNDAwMTM5fQ.gma3YeCj8-TYGbTTO1pUbBUepcO2RAxTSH34D2DdcZM')
			// setAccToken('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MzE0NiwiZXhwIjoxNzAwNDcwNjcyfQ.I7W0CoQpXaTnQedUbMMn72SZN2iZ-wQ3TrcKo4VyZtw')
			let locationUrl = window.location.href;
			var token = this.getval(locationUrl,"token");
			token = token.replace(/\s+/g, '+')
			if(token){
				token = JSON.parse(token)
				setAccToken(token)
			}
			
			
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			getval(url, name){
				var reg = new RegExp("(^|\\?|&)"+ name +"=([^&|#]*)(\\s|&|#|$)", "i");  // 因为vue有添加“#”的特点，所以这里的正则表达式会匹配 & -- &/#
				if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, " "));
				return "";
			},
			isOpenMode() {
				//平台、设备和操作系统
				var system = {
					win: false,
					mac: false,
					xll: false,
					ipad: false
				};
				//检测平台
				var p = navigator.platform;
				system.win = p.indexOf("Win") == 0;
				system.mac = p.indexOf("Mac") == 0;
				system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
				system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
				if (system.win || system.mac || system.xll || system.ipad) {
					var ua = navigator.userAgent.toLowerCase();
					if (ua.match(/MicroMessenger/i) == "micromessenger") {
						
					} else {
						alert("请在微信中浏览餐品哦");
						window.location.href = 'http://www.shffcs.com/'
						return 3;
					}
				} else {
					var ua = navigator.userAgent.toLowerCase();
					if (ua.match(/MicroMessenger/i) == "micromessenger") {
						
					} else {
						alert("请在微信中浏览餐品哦");
						window.location.href = 'http://www.shffcs.com/'
						return 4;
					}
				}
			}
		}
	};
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '~@/static/style/app.scss';
	@import 'uni_modules/uview-ui/index.scss';
	.t1{
		color: #000;font-size: 16px;
	}
	page{
		// background: #f5f2f0 !important;
		background: #f5f5f5 !important;
	}
</style>